package mobmap.splash;

import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class SplashScreen extends Canvas {
    
	private Display     display;
    private Displayable next;
    private Timer       timer = new Timer();
    private Image splash;

    public SplashScreen(Display display, Displayable next ){
        setFullScreenMode(true);
    	this.display = display;
        this.next    = next;
        
        try {
			splash = Image.createImage("/rsc/splash.png");
		} catch (IOException e) {}
		
		display.setCurrent( this );
    }

    protected void keyPressed( int keyCode ){
        dismiss();
    }

    protected void paint( Graphics tela ){
    	tela.setColor(255, 255, 255);
		tela.fillRect(0, 0, getWidth(), getHeight());
		tela.drawImage(splash, getWidth () / 2, getHeight () / 2, 
		           Graphics.HCENTER | Graphics.VCENTER);
    
    }

    protected void pointerPressed( int x, int y ){
        dismiss();
    }

    protected void showNotify(){
        timer.schedule( new CountDown(), 1500 );
    }

    private void dismiss(){
        timer.cancel();
        display.setCurrent( next );
    }

    private class CountDown extends TimerTask {
        public void run(){
            dismiss();
        }
    }
}
